<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title></title>
   <%@include file="/WEB-INF/jsp/component/commonHead.jsp" %>
   <!-- DataTables CSS -->
    <link href="${css}/dataTables.bootstrap.css" rel="stylesheet">
    <!-- DataTables Responsive CSS -->
    <link href="${css}/dataTables.responsive.css" rel="stylesheet">
    <!-- theme1.0 css -->
    <link href="${theme}/style/person.css" rel="stylesheet">
</head>
<body  id="body">
<div id="form">
		<input type="text" value="" name="realName" id="realName" placeholder="姓名" />
		<input type="text" value="" name="ageNum"  id="ageNum" placeholder="年龄"/>
		<select name="sex" id="sex" >
		    <option value="-1">性别</option>
			<option value="1" >男</option>
			<option value="0" >女</option>	
		</select>
		<input type="text" class="card" value="" name="card" id="card" placeholder="身份证号" />
		<button onclick="search()" ></button>
</div>
<div class="cl"></div>
 <table style="" cellSpacing=0 cellPadding=0   border=0">
 <thead>
 <tr><th colspan="7">患者体检数据</th></tr>
 </thead>
 <tbody>
 <tr>
 <td>
 <table class="" id="dataTables" style="margin-top:-1px !important;margin-bottom:-1px !important;">
     <thead>
     <tr style="" >
         <td style="diplay:none;">id</td>
         <td style="background-color: white;">患者姓名</td>
         <td style="background-color: white;">性别</td>
         <td style="background-color: white;">年龄</td>
         <td style="background-color: white;">身份证号</td>
         <td style="background-color: white;">体检编号</td>
         <td style="background-color: white;">上次体检时间</td>
     </tr>
     </thead>
     <tbody>
      
     </tbody>
     <tfoot>
       <tr><td colspan="7" class="last" id="twbsPagination" ><ul id="pagination" class="pagination-sm" ></ul></td></tr>
     </tfoot>
 </table>
 </td>
 </tr>
 </tbody>
 </table>
 <%@include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
  <!-- DataTables JavaScript -->
    <script src="${js}/jquery.twbsPagination.min.js"></script>
    <script>
    var totalPages;
	var startPage;
    $(document).ready(function(){
    	initTable();
    	selectData();
    });
    var page_size = totalPages;
    function page(){
   	 	$('#pagination').twbsPagination({
   	        totalPages: totalPages,
   	        startPage: startPage,
   	        visiblePages: 7,
   	        first: '首页',
   	        last: '末页',
   	        prev: '上一页',
   	        next: '下一页',
   	        onPageClick: function (event, page) {
   	            startPage = page;
   	            selectData();
   	        }
   	    });
    }
    function initTable(){
    	$('#dataTables').dataTable({
    		    "bInfo": false, //页脚信息
    		    "bPaginate":false, //分页
    		    "bFilter": false, //过滤功能
    			"aoColumns":[
					{ "mData": "id" ,
					  "orderable": false,
					  "bVisible": false,
					  "sDefaultContent" : ""
					},
					{ "mData": "realname" ,
					  "orderable": false,
					  "sDefaultContent" : ""
					},
					{ "mData": "gender",
		              "orderable": false ,
		              "sDefaultContent" : "",
		              "mRender": function(data, type, full){
		            	  if(data=="1"){
		                	return "男";
		            	  }else if(data=="2"){
		            		  return "女";
		            	  }else{
		            		  return "-";
		            	  }
		                }  
					},
					{ "mData": "age" ,
		               "orderable": false,
		               "sDefaultContent" : "",
		               "mRender": function(data, type, full){
			            	  if(data!=null){
			                	return data;
			            	  }else{
			            		  return "-";
			            	  }
			                }  
		            },
					{ "mData": "idCard",
		               "orderable": false,
		               "sDefaultContent" : "",
		               "mRender": function(data, type, full){
		            	   if(data=="undefined"||data==null||data==""){
		            		   return "-";
		            	   }else{
		            		   var inner = "<a href='#' onclick=selectExam('"+data+"') >"+data+"</a>";
				               return inner;
		            	   }
			            }     
					},
		            {  "mData": "mkExamCode",
					   "sDefaultContent" : "",
			           "orderable": false,
			           "mRender": function(data, type, full){
			        	   if(data=="undefined"||data==null||data==""){
			        		   return "-";
			        	   }else{
			        		   var inner = "<a href='#' onclick=showDetail('"+full.mkExamCode+"','"+full.idCard+"') >"+data+"</a>";
				               return inner;  
			        	   }
			            }     
			        },
			        {  "mData": "examDateStr",
			           "sDefaultContent" : "",
				       "orderable": false}
				]
   	 });
    }
   
function selectData(){
	var realName = $("#realName").val();
	var ageNum = $("#ageNum").val();
	var sex = $("#sex").val();
	var idCard = $("#card").val();
	
	var ajaxUrl = "${ctx}/Exam/listPatients";
  	$.ajax({
	    type:"post",
	    url:ajaxUrl,
	    data:{
	    	size:10, //每页条数
	    	page:startPage, //当前页
	    	realName:realName,
	    	ageNum:ageNum,
	    	sex:sex,
	    	card:idCard
	    },
	    dataType: "json",
	    success:function(json){
	    	 //var da = JSON.stringify(json);
	    	 //$("#content").html(da);
	    	if(page_size!=json.totalPages){  
		        $("#twbsPagination").html('<ul id="pagination" class="pagination-sm" ></ul>');  
		    } 
	    	totalPages = json.totalPages;
	    	page_size = totalPages;
	    	 startPage = json.number+1;
	    	 $('#dataTables').dataTable().fnClearTable(); 
	    	 $('#dataTables').dataTable().fnAddData(json.content,true);
	    	 page();
	    },
	    complete:function () {
            //修改iframe高度
            reSizeParentIframe();
        } 
	});
}

	function selectExam(idCard){
	    var url = "${ctx}/Exam/init?obj=exams1&idCard="+idCard;
	    window.location.href = url;
	}
	
	function search(){
		startPage = 1;
		selectData();
	}
	
	function showDetail(code,card){
		 var url = "${ctx}/Exam/showDetail?idCard="+card+"&mkCode="+code;
		 window.location.href = url;
	}
</script>
</body>
</html>
